package com.qidian.buy.goods.config.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2023/9/15 13:40
 */
@Configuration
public class ItemQueueConfig {
    // 添加商品的时候发送消息的直连交换机
    @Bean
    public DirectExchange itemAddDirectExchange(){
        // 添加商品的交换机
        return new DirectExchange("item-direct-exchange",true,false);
    }
    // 配置对应的队列
    @Bean
    public Queue itemAddDetail(){
        return new Queue("item-detail");
    }
    @Bean
    public Queue itemAddSearch(){
        return new Queue("item-search");
    }
    // 绑定队列到交换机
    @Bean
    public Binding bindingItemAddDetail(){
        return BindingBuilder.bind(itemAddDetail()).to(itemAddDirectExchange()).with("item");
    }
    @Bean
    public Binding bindingItemAddSearch(){
        return BindingBuilder.bind(itemAddSearch()).to(itemAddDirectExchange()).with("item");
    }
}
